package it.univaq.mancoosi.injectors.systemconfiguration.managers;

import it.univaq.mancoosi.injectors.systemconfiguration.managers.ubuntu.UbuntuEnvironmentManager;
import it.univaq.mancoosi.mancoosimm.MancoosiFactory;
import it.univaq.mancoosi.mancoosimm.Rule;
import it.univaq.mancoosi.mancoosimm.Udev;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;

public abstract class UdevManager {

	protected static UdevManager INSTANCE;
	protected MancoosiFactory factory;
//	protected Udev udev;
	protected HashMap<String, Rule> ruleMap; 

	protected UdevManager(){
		factory = MancoosiFactory.eINSTANCE;
//		udev = factory.createUdev();
		this.ruleMap = new HashMap<String, Rule>();
	}

	public static UdevManager getInstance() {
		return INSTANCE;
	}

	public abstract void createUdevFromSystem();
	
//	public Udev getUdev () {
//		return this.udev;
//	}
	
	public abstract Boolean exists(String ruleName);

	public abstract void synchronize() throws IOException;
	
	public void syncMap () {
		Iterator<Rule> iterator  = null;
		if(UbuntuEnvironmentManager.getInstance().getEnvironment().getUdev() != null){
			iterator = UbuntuEnvironmentManager.getInstance().getEnvironment().getUdev().getRules().iterator();
		}
		if(iterator != null){
			while (iterator.hasNext()) {
				Rule curr = iterator.next();
				this.ruleMap.put(curr.getName(), curr);
			}
		}
	}
}
